<?php

class Blog extends __Controller {

	function __construct() {
		
		parent::__construct();
		
		$this->data->title = "Wani's Blog";
		$this->data->href = "http://".HOME."/blog";
		$this->data->library = "http://".HOME."/library";
		$this->data->description = "창완이의 블로그 :D";

		$this->load->module('input', $this->input);
		$this->load->module('mysql', $this->db);
		
		$this->load->helper('string');
		$this->load->helper('url');
				
		$escaped = $this->input->get('_escaped_fragment_');
		
		if ( $escaped ) {
			$row = $this->db->result("select * from `wd_data` where `idx`='".trim( $escaped, "/" )."'");
			$this->data->title .= " - " . $row['subject'];
			$this->data->description =  str_cut( strip_tags($row['contents']) , 400 );
			//$this->data['description'] =  str_replace(array('\r','\n'), array('',''), $this->data['description']);
		}
	}

	function index() {

		if ( substr($_SERVER['PHP_SELF'], -1) != '/' ) go( "http://".SELF ."/" );
		
		$page = max( (int)$this->input->get("page", 1), 1);
		
		$this->data->category	= $this->db->fetch_assoc("select `idx`,`name` from `wd_category` where `board_id`='blog' order by `order` desc");
		$this->data->rows		= $this->db->fetch_assoc("select * from `wd_data` where `board_id`='blog' order by `idx` desc limit ".(($page-1)*10).", 10");

		$this->data->next = $page + 1;
		$this->load->view( 'blog/index' );

	}

}